package cn.com.inossem.operation;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.os.Bundle;
import cn.com.inossem.config.WSConfig;
import cn.com.inossem.model.LoginresultData;
import cn.com.inossem.network.NetworkConnect;
import cn.com.inossem.requestmanager.WooRequestFactory;
import cn.com.inossem.utils.Utils;

import com.foxykeep.datadroid.exception.ConnectionException;
import com.foxykeep.datadroid.exception.CustomRequestException;
import com.foxykeep.datadroid.exception.DataException;
import com.foxykeep.datadroid.requestmanager.Request;
import com.foxykeep.datadroid.service.RequestService.Operation;
import com.google.gson.Gson;

public class WangjimimaOperation implements Operation {
	public static Bundle bundle;

	public static final String REGISTERED_OPERATION_USERNAME = "registered_operation_username";
	public static final String REGISTERED_OPERATION_PASSWORD = "registered_operation_password";
	public static final String REGISTERED_OPERATION_VALIDCODE = "registered_operation_validcode";

	@Override
	public Bundle execute(Context arg0, Request request)
			throws ConnectionException, DataException, CustomRequestException {

		String uName = request.getString(REGISTERED_OPERATION_USERNAME);
		String uPWD = request.getString(REGISTERED_OPERATION_PASSWORD);
		String validcode = request.getString(REGISTERED_OPERATION_VALIDCODE);

		NetworkConnect connection = new NetworkConnect(WSConfig.LOCAL_URL
				+ "userInfo/forgetPWD");
		connection.setPostText("{\"phone\":\"" + uName
				+ "\",\"newPassword\":\"" + uPWD + "\",\"validcode\":\""
				+ validcode + "\"}");
		System.out.println("{\"phone\":\"" + uName + "\",\"newPassword\":\""
				+ uPWD + "\",\"validcode\":\"" + validcode + "\"}");
		String body = connection.execute();

		System.out.println("WangjimimaOperation:" + body);
		bundle = new Bundle();
		try {
			JSONObject jsonObject = new JSONObject(body);
			int errorFlag = jsonObject.getInt("errorFlag");
			// List<SkillsInfoBean> retList;
			if (errorFlag == WSConfig.RESULT_SUCESS) {

			} else {
				// retList = null;
			}
			// 返回返回值
			// bundle.putParcelableArrayList(
			// WooRequestFactory.RESPONSE_SKILLS_DATA,
			// (ArrayList<? extends Parcelable>) retList);
			// // 设置结果
			bundle.putInt(WooRequestFactory.BUNDLE_EXTRA_WANGJIMIMA, errorFlag);
		} catch (JSONException e) {
			e.printStackTrace();
		}

		return bundle;
	}
}
